package com.youku.plugins.Tips.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.plugins.PluginEventDispather;
   import flash.utils.Dictionary;
   import com.youku.events.PluginEvent;
   import com.youku.plugins.Tips.TipsEvent;
   import flash.utils.setTimeout;
   import flash.events.Event;
   
   public class TipsMediator extends Object
   {
      
      public function TipsMediator(param1:MovieClip, param2:IPlayerProxy, param3:PluginEventDispather) {
         super();
         this._mainMC = param1;
         this._playerProxy = param2;
         this._tipsEventManager = param3;
         this._dict = new Dictionary();
         this.addEvents();
      }
      
      private var _mainMC:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _tipsEventManager:PluginEventDispather;
      
      private var _dict:Dictionary;
      
      private var _isShowed:Boolean;
      
      private var _showTimes:Number = 10000.0;
      
      private var _isRegister:Boolean;
      
      private function addEvents() : void {
         this._playerProxy.addEventListener(PluginEvent.TIPS_REGISTER,this.onRegiste);
         this._playerProxy.addEventListener(PluginEvent.TIPS_SHOW,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.TIPS_HIDE,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.TIPS_CHANGE_SIZE,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_STATE_MINI,this.hideAll);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_START_HIDE,this.hideAll);
         this._tipsEventManager.addEventListener(TipsEvent.CLOSE_CLICK,this.onKnowClick);
         this._tipsEventManager.addEventListener(TipsEvent.KNOW_CLICK,this.onKnowClick);
      }
      
      private function onRegiste(param1:PluginEvent) : void {
         var _loc2_:String = param1.data.key as String;
         var _loc3_:String = param1.data.text as String;
         var _loc4_:Tips = new Tips(_loc2_,_loc3_,this._playerProxy,this._tipsEventManager);
         this._dict[_loc2_] = _loc4_;
         this._isRegister = true;
      }
      
      private function onPluginEvent(param1:PluginEvent) : void {
         var _loc2_:String = null;
         var _loc3_:Tips = null;
         _loc2_ = param1.data.key;
         if(!this._isRegister || this._dict[_loc2_] == null)
         {
            return;
         }
         switch(param1.type)
         {
            case PluginEvent.TIPS_SHOW:
               if(!this._playerProxy.fsoProxy.getTipsSetting(_loc2_) && !this._isShowed)
               {
                  this.show(_loc2_);
                  this._isShowed = true;
                  setTimeout(this.hide,this._showTimes,_loc2_);
               }
               break;
            case PluginEvent.TIPS_HIDE:
               this.hide(_loc2_);
               break;
            case PluginEvent.TIPS_CHANGE_SIZE:
               _loc3_ = this._dict[_loc2_];
               _loc3_.update(param1.data.point,param1.data.playerWidth);
               break;
         }
      }
      
      private function onKnowClick(param1:TipsEvent) : void {
         var _loc2_:String = param1.data as String;
         this.hide(_loc2_);
         this._playerProxy.fsoProxy.saveTipsSetting(_loc2_);
      }
      
      private function show(param1:String) : void {
         this._mainMC.addChild(this._dict[param1] as Tips);
      }
      
      private function hide(param1:String) : void {
         if(this._mainMC.contains(this._dict[param1] as Tips))
         {
            this._mainMC.removeChild(this._dict[param1] as Tips);
         }
      }
      
      private function hideAll(param1:Event = null) : void {
         var _loc2_:Tips = null;
         for each(_loc2_ in this._dict)
         {
            if(this._mainMC.contains(_loc2_))
            {
               this._mainMC.removeChild(_loc2_);
            }
         }
      }
   }
}
